Managing Web Server Configuration Files
Although
making configuration settings on one or a few servers is easiest using
graphical tools, systems administrators often need to configure many
Web servers. In addition to using IIS Manager and related tools for
configuring settings, you can also configure your Web server by using
XML configuration files. In addition, by storing settings in a single
file, you can back up and restore settings to other IIS installations
easily. In this section, you’ll learn about where Web server and Web
site settings are stored.
Understanding ApplicationHost.config
All the configuration settings that have been defined for the local IIS Web server are stored in an XML text file named ApplicationHost.config. The default file system location for these files is %SystemDrive%\Inetpub\History. Within this base folder is a series of folders, each of which contains a copy of the ApplicationHost.config file.
The ApplicationHost Helper Service, a default component that is
included when you install the Web Server (IIS) role, automatically
makes periodic backups of the configuration of the local Web server.
This process automatically creates a new folder and a copy of the
ApplicationHost.config file. The schema subfolder contains a file that
is used to describe and interpret the specific settings that can be
used in the configuration files.
An
ApplicationHost.config file can be opened and modified, using a
standard text editor (such as Windows Notepad) or by using an XML-aware
application (such as Visual Studio). The contents are arranged in a
hierarchy that defines the various settings and options that can be
configured within IIS. (See Figure 19.)
Before you make changes directly to a configuration file, be sure to
make a backup copy of it. It is fairly easy to introduce changes that
can cause errors in IIS.
Restoring the ApplicationHost.config File
In
the event that you need to revert the configuration of IIS to an
earlier state by using the automatic backup files, you can copy over
the working config file manually. The active version of the
ApplicationHost.config file is in the %SystemRoot%\System32\Inetsrv\Config
folder. To roll back the configuration of IIS, find the
ApplicationHost.config version you want to use and then copy it over
the current file. Note that for the changes to be reflected, it might
be necessary to restart the Web server and IIS Manager. It is also
highly recommended that you copy the current configuration file to a
backup location in the event you need to refer to it later.
Understanding Web.config Files
A
common problem related to managing Web applications and Web sites is
that of retaining settings as sites are moved between servers. In
previous versions of IIS, it was often necessary to re-create settings
manually to ensure that the site would run properly. IIS 7.0 uses a
hierarchical approach to create and manage configuration settings. In
addition to the server-level settings that are defined in the
ApplicationHost.config file, systems administrators and Web developers
can include other settings in Web.config files.
Web.config files
can be located within the root folder for a Web site or Web
application. These files can contain settings that override the default
server-level settings that are included in the ApplicationHost.config
file. The format of the files and options is similar. By default, a new
Web.config file is created automatically whenever you add a new Web
site or a new Web application. The default settings are inherited from
the server-level settings unless you specifically change them.
Overall, the hierarchy for configuration files is:
Host (ApplicationHost.config)
Settings
in lower-level files can override settings defined in the parent. A
useful benefit of this approach is that the configuration information
is included automatically when you choose to copy an entire folder of
Web content to another server or to another location on the same server.
Tip
When
making changes to IIS and Web application configurations, consider
which portions of the site structure the modifications should affect.
If the goal is to modify all Web sites, consider making the change in
the server-level ApplicationHost.config file. Otherwise, making
site-level or application-level changes will likely be more appropriate.
Migrating Web Sites and Web Applications
The
presence of Web.config files within Web application and Web site
folders helps make the process of migrating Web sites to different
servers or physical locations simpler. For most applications, all that
is required is for all the files within the appropriate folders to be
moved or copied to the new location. Then, within IIS Manager, you can
re-create any additional Web sites, Web applications, and virtual
directories that are required. It is important, however, to test any
migrated Web application thoroughly. In some cases, incompatibilities
or other issues between server-level and application-level settings can
have unintended consequences. Overall, however, the process of moving
and copying Web sites is usually fairly simple and straightforward.
Backing Up and Restoring Configuration Data Using AppCmd.exe
An
important aspect of Web server administration is ensuring that the
configuration of the server is protected against data loss. Because IIS
configuration settings are stored automatically in the %SystemDrive%\Inetpub\History
folder, ensure that this folder is included in file system backup
policies. In addition, it’s important to back up Web sites and Web
applications to ensure that they can be restored quickly in the case of
a failure. Often, however, you’ll need to create your own configuration
backups manually. For example, if you want to transfer configuration
data to another IIS installation, or if you want to protect against
unwanted changes, it is a good idea to make an on-demand configuration
backup.
You can use
AppCmd.exe to create a backup of the configuration of IIS and store it
to a text file. The utility offers simple capabilities for creating a
backup and for restoring from it. The standard command for adding a new
backup is:
AppCmd add backup "BackupName"
BackupName
specifies the name of the file that you want to create. You can leave
off the name, and an automatic filename that includes a timestamp will
be generated. The file will be created in the location in which
AppCmd.exe was run, but you can always move or copy the file manually
to another location.
You can restore the configuration information from the backup, using the following command:
AppCmd restore backup "BackupName"
This
process restores the configuration of the IIS Web server to the
settings that were included in the backup file. If you want to view a
list of backups that have been made, you can use the following command:
You will see a list of all the backup files you have created. Figure 20 shows an example of all these backup-related commands at work.
Using Centralized Configuration for Server Farms
As
organizations place a greater reliance on their Web sites and Web-based
applications, the ability to improve performance, scalability, and
reliability are important goals. With relation to Web servers, a common
configuration is known as a Web server farm.
In this approach, many Web servers are configured to provide access to
the same content. Generally, they have the same configuration settings
and either store local copies of Web sites and applications or access
them from a shared location.
From
a systems administration standpoint, managing large groups of Web
servers can be challenging. When configuration changes are required,
they often have to be committed manually to many computers. Even with
the use of automation or scripting, it is possible to overlook one or a
few servers. To support the server farm usage scenario better, IIS 7.0
enables you to share centrally stored configuration data with multiple
Web servers.
The
first step in the process of creating a shared configuration is to
export the configuration of a single IIS server. Generally, you will
configure this server with all the settings that you want to use on the
other servers. Then, using IIS Manager, click the server name and
double-click Shared Configuration in the Features View. To generate an
export, click the Export Configuration command in the Actions pane.
(See Figure 21.)
You will be able to provide a path into which the configuration files
will be stored. To protect sensitive information in the configuration
files, you must type and confirm an encryption key password. This
password will be required to view the settings in the file. You can
also use the Connect As option to provide security credentials if you
are planning to store the configuration in a network location.
The
second step of the process is to place the shared configuration file in
a location that is accessible to all the Web servers. Usually, the best
choice is a shared network folder on a reliable server. Once you know
the path to the files, you can use the Shared Configuration feature to
enter the details. First, select the Enable Shared Configuration check
box. (See Figure 22.)
This will enable you to specify the Physical Path setting. You can use
a local file system location or a Universal Naming Convention
(UNC)–based network path (for example, \\Server1\WebConfig). The User
Name and Password fields enable you to enter the security credentials
that will be used by IIS to connect to the physical path you have
specified.
To
save the settings, click the Apply command in the Actions pane. You
will be prompted to enter the encryption key password for the
configuration files. Once the configuration import is complete, you
will be notified that you must restart IIS Manager for it to recognize
the configuration changes. You can disable the shared configuration
settings later by deselecting the Enable Shared Configuration check
box. This returns the Web server to using locally defined configuration
settings.
More Info: Creating production server farms
The ability to share settings easily among Web servers is helpful for setting up IIS-based Web server farms.
However, sharing configuration data is only one part of an overall Web
server farm configuration. Other considerations include deploying and
synchronizing content updates, handling session state, managing
security, implementing load-balancing, and responding to fail-over
events. Rest assured, there are many good ways of addressing these
challenges. However, always be sure to involve Web developers and
systems administrators when designing a scale-out strategy.